package com.neiquan.neiquandemo.test;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.neiquan.neiquandemo.R;
import com.yzq.zxinglibrary.android.CaptureActivity;
import com.yzq.zxinglibrary.bean.ZxingConfig;
import com.yzq.zxinglibrary.common.Constant;
import com.yzq.zxinglibrary.encode.CodeCreator;

import net.neiquan.applibrary.base.BaseSiderBarFragment;
import net.neiquan.applibrary.bean.SortModel;
import net.neiquan.applibrary.utils.CharacterParser;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wl_user on 2017/7/25.
 */

public class SiderBarFragment extends BaseSiderBarFragment {
    @Override
    public List<SortModel> filledData(CharacterParser characterParser) {
        String[] datas = getResources().getStringArray(R.array.date);
        List<SortModel> mSortList = new ArrayList<SortModel>();
        for (int i = 0; i < datas.length; i++) {
            SortModel sortModel = new SortModel();
            sortModel.setName(datas[i]);
            // 汉字转换成拼音
            String pinyin = characterParser.getSelling(datas[i]);
            String sortString = pinyin.substring(0, 1).toUpperCase();
            // 正则表达式，判断首字母是否是英文字母
            if (sortString.matches("[A-Z]")) {
                sortModel.setSortLetters(sortString.toUpperCase());
            } else {
                sortModel.setSortLetters("#");
            }
            mSortList.add(sortModel);
        }
        return mSortList;
    }

    @Override
    public void onItemClickListener(int position, SortModel model) {
//        startActivity(new Intent(getActivity(),TwoActivity.class));
        Intent intent = new Intent(getActivity(), CaptureActivity.class);
        ZxingConfig config = new ZxingConfig();
        config.setPlayBeep(true);//是否播放扫描声音 默认为true
        config.setShake(true);//是否震动  默认为true
        config.setDecodeBarCode(true);//是否扫描条形码 默认为true
        config.setReactColor(R.color.colorAccent);//设置扫描框四个角的颜色 默认为白色
        config.setFrameLineColor(R.color.colorAccent);//设置扫描框边框颜色 默认无色
        config.setScanLineColor(R.color.colorAccent);//设置扫描线的颜色 默认白色
        config.setFullScreenScan(false);//是否全屏扫描  默认为true  设为false则只会在扫描框中扫描
        intent.putExtra(Constant.INTENT_ZXING_CONFIG, config);
        startActivityForResult(intent, 1);

        /* 生成二维码
         *contentEtString：字符串内容
         * w：图片的宽
         * h：图片的高
         * logo：不需要logo的话直接传null
         * */
//        Bitmap logo = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
//        bitmap = CodeCreator.createQRCode(contentEtString, 400, 400, logo);
    }

//    @Override
//    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//
//        // 扫描二维码/条码回传
//        if (requestCode == 1 && resultCode == RESULT_OK) {
//            if (data != null) {
//
//                String content = data.getStringExtra(Constant.CODED_CONTENT);
//                result.setText("扫描结果为：" + content);
//            }
//        }
//    }

    @Override
    public boolean isHaveHead() {
        return true;
    }

    @Override
    public void init() {
        setTitleTv("选择城市");
    }
}
